package com.gxa.meiye.sso.service.impl;

import com.aliyuncs.exceptions.ClientException;
import com.gxa.meiye.sso.service.SmsService;
import com.gxa.meiye.sso.utils.SendSm;
import com.gxa.meiye.sso.utils.SendSms;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * @Author: zy
 * @CreateTime: 2022-07-19  20:52
 */
@Service
@Transactional(rollbackFor = Throwable.class)
public class SmsServiceImpl implements SmsService {
    public static final String LOGIN_SMS="login_sms:";

    @Autowired
    private RedisTemplate<String,Object> redisTemplate = null;

    @Override
    public String smsSendLogin(String phone) throws ClientException {
        String msgCode = SendSm.getMsgCode();
        //发送短信
        //SendSm.Send(phone,msgCode,15);
        System.out.println(msgCode);
        redisTemplate.opsForValue().set(LOGIN_SMS+phone,msgCode,15, TimeUnit.MINUTES);
        //String templateParam="{\"code\":"+msgCode+"}";
        //SendSms.sendSms(phone,"SMS_204986028",templateParam);
        return msgCode;
    }
}
